|
|
|
|
|
|
|
Figure 9.4
A call by value. |
|
|
|
|
|
|
|
|
Visual Basic allows you to create optional arguments in the declaration of a procedure. This means you can call the procedure either with or without these parameter. You have two methods for specifying optional arguments. Lets look at both of them. |
|
|
|
|
|
|
|
|
You can create an optional variant argument, as shown in the following code. When you use a variant in the declaration and the procedure is called without the parameter, an Empty value will be assigned to the variant. You can test for this Empty value by using the built-in Visual Basic function IsMissing(). Heres a procedure with this type of definition: |
|
|
|
 |
|
|
|
|
Public Sub ProcOptionalVar(ByVal intFirst As Integer, _
ByVal intSecond As Integer, _
Optional vntName As Variant)
If IsMissing(vntName) Then vntName = "Default Name"
End If
MsgBox vntName
End Sub |
|
|
|
|
|